package service.impl;

import dao.AccountDao;
import dao.impl.AccountDaoImpl;
import domain.Account;
import org.apache.ibatis.session.SqlSession;
import service.AccountService;
import utils.SqlSessionUtil;

public class AccountServiceImpl implements AccountService {
    @Override
    public void transfer() {


    }

    @Override
    public void updateBalance(Integer id, Double money) {
        SqlSession sqlSession = SqlSessionUtil.openSession();
        Account account = sqlSession.selectOne("selectById", id);
        Double balance = account.getBalance();
        balance += money;
        account.setBalance(balance);
        sqlSession.update("updateAccount",account);
        sqlSession.commit();
        System.out.println(account);
    }

    @Override
    public void updateBalance2(Integer id, Double money) {
        SqlSession sqlSession = SqlSessionUtil.openSession();
        Account account = sqlSession.selectOne("selectById", id);
        Double balance = account.getBalance();
        balance += money;
        account.setBalance(balance);
        sqlSession.update("updateAccount",account);
        sqlSession.commit();
        System.out.println(account);
    }

    @Override
    public Account getAccountById(Integer id) {
        SqlSession sqlSession = SqlSessionUtil.openSession();
        Account account = sqlSession.selectOne("selectById", id);
        return account;
    }
}
